package com.openbravo.editor;

import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.EventListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.EventListenerList;

public class JEditorKeys extends JPanel
  implements EditorKeys
{
  private static final char[] SET_DOUBLE = { '', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-' };
  private static final char[] SET_DOUBLE_POSITIVE = { '', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.' };
  private static final char[] SET_INTEGER = { '', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-' };
  private static final char[] SET_INTEGER_POSITIVE = { '', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  protected EventListenerList listeners = new EventListenerList();
  private EditorComponent editorcurrent;
  private char[] keysavailable;
  private boolean m_bMinus;
  private boolean m_bKeyDot;
  JButton m_jCE;
  JButton m_jKey0;
  JButton m_jKey1;
  JButton m_jKey2;
  JButton m_jKey3;
  JButton m_jKey4;
  JButton m_jKey5;
  JButton m_jKey6;
  JButton m_jKey7;
  JButton m_jKey8;
  JButton m_jKey9;
  JButton m_jKeyDot;
  JButton m_jMinus;
  JTextField m_txtKeys;

  public JEditorKeys()
  {
    initComponents();
    this.m_jKey0.addActionListener(new MyKeyNumberListener('0'));
    this.m_jKey1.addActionListener(new MyKeyNumberListener('1'));
    this.m_jKey2.addActionListener(new MyKeyNumberListener('2'));
    this.m_jKey3.addActionListener(new MyKeyNumberListener('3'));
    this.m_jKey4.addActionListener(new MyKeyNumberListener('4'));
    this.m_jKey5.addActionListener(new MyKeyNumberListener('5'));
    this.m_jKey6.addActionListener(new MyKeyNumberListener('6'));
    this.m_jKey7.addActionListener(new MyKeyNumberListener('7'));
    this.m_jKey8.addActionListener(new MyKeyNumberListener('8'));
    this.m_jKey9.addActionListener(new MyKeyNumberListener('9'));
    this.m_jKeyDot.addActionListener(new MyKeyNumberListener('.'));
    this.m_jCE.addActionListener(new MyKeyNumberListener(''));
    this.m_jMinus.addActionListener(new MyKeyNumberListener('-'));
    this.editorcurrent = null;
    setMode(0);
    doEnabled(false);
  }

  public void setComponentOrientation(ComponentOrientation paramComponentOrientation)
  {
  }

  public void addActionListener(ActionListener paramActionListener)
  {
    this.listeners.add(ActionListener.class, paramActionListener);
  }

  public void removeActionListener(ActionListener paramActionListener)
  {
    this.listeners.remove(ActionListener.class, paramActionListener);
  }

  protected void fireActionPerformed()
  {
    EventListener[] arrayOfEventListener = this.listeners.getListeners(ActionListener.class);
    ActionEvent localActionEvent = null;
    for (int i = 0; i < arrayOfEventListener.length; i++)
    {
      if (localActionEvent == null)
        localActionEvent = new ActionEvent(this, 1001, null);
      ((ActionListener)arrayOfEventListener[i]).actionPerformed(localActionEvent);
    }
  }

  private void doEnabled(boolean paramBoolean)
  {
    this.m_jKey0.setEnabled(paramBoolean);
    this.m_jKey1.setEnabled(paramBoolean);
    this.m_jKey2.setEnabled(paramBoolean);
    this.m_jKey3.setEnabled(paramBoolean);
    this.m_jKey4.setEnabled(paramBoolean);
    this.m_jKey5.setEnabled(paramBoolean);
    this.m_jKey6.setEnabled(paramBoolean);
    this.m_jKey7.setEnabled(paramBoolean);
    this.m_jKey8.setEnabled(paramBoolean);
    this.m_jKey9.setEnabled(paramBoolean);
    this.m_jKeyDot.setEnabled((paramBoolean) && (this.m_bKeyDot));
    this.m_jCE.setEnabled(paramBoolean);
    this.m_jMinus.setEnabled((paramBoolean) && (this.m_bMinus));
  }

  public void setMode(int paramInt)
  {
    switch (paramInt)
    {
    case 1:
      this.m_bMinus = true;
      this.m_bKeyDot = true;
      this.keysavailable = SET_DOUBLE;
      break;
    case 2:
      this.m_bMinus = false;
      this.m_bKeyDot = true;
      this.keysavailable = SET_DOUBLE_POSITIVE;
      break;
    case 3:
      this.m_bMinus = true;
      this.m_bKeyDot = false;
      this.keysavailable = SET_INTEGER;
      break;
    case 4:
      this.m_bMinus = false;
      this.m_bKeyDot = false;
      this.keysavailable = SET_INTEGER_POSITIVE;
      break;
    case 0:
    default:
      this.m_bMinus = true;
      this.m_bKeyDot = true;
      this.keysavailable = null;
    }
  }

  public void setActive(EditorComponent paramEditorComponent, int paramInt)
  {
    if (this.editorcurrent != null)
      this.editorcurrent.deactivate();
    this.editorcurrent = paramEditorComponent;
    setMode(paramInt);
    doEnabled(true);
    this.m_txtKeys.setText(null);
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        JEditorKeys.this.m_txtKeys.requestFocus();
      }
    });
  }

  public void setInactive(EditorComponent paramEditorComponent)
  {
    if ((paramEditorComponent == this.editorcurrent) && (this.editorcurrent != null))
    {
      this.editorcurrent.deactivate();
      this.editorcurrent = null;
      setMode(0);
      doEnabled(false);
    }
  }

  private void initComponents()
  {
    this.m_jKey0 = new JButton();
    this.m_jKey1 = new JButton();
    this.m_jKey4 = new JButton();
    this.m_jKey7 = new JButton();
    this.m_jCE = new JButton();
    this.m_jMinus = new JButton();
    this.m_jKey9 = new JButton();
    this.m_jKey8 = new JButton();
    this.m_jKey5 = new JButton();
    this.m_jKey6 = new JButton();
    this.m_jKey3 = new JButton();
    this.m_jKey2 = new JButton();
    this.m_jKeyDot = new JButton();
    this.m_txtKeys = new JTextField();
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new GridBagLayout());
    this.m_jKey0.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn0.png")));
    this.m_jKey0.setFocusPainted(false);
    this.m_jKey0.setFocusable(false);
    this.m_jKey0.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey0.setRequestFocusEnabled(false);
    GridBagConstraints localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 4;
    localGridBagConstraints.gridwidth = 2;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 0, 0, 0);
    add(this.m_jKey0, localGridBagConstraints);
    this.m_jKey1.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn1.png")));
    this.m_jKey1.setFocusPainted(false);
    this.m_jKey1.setFocusable(false);
    this.m_jKey1.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey1.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 3;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 0, 0, 0);
    add(this.m_jKey1, localGridBagConstraints);
    this.m_jKey4.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn4a.png")));
    this.m_jKey4.setFocusPainted(false);
    this.m_jKey4.setFocusable(false);
    this.m_jKey4.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey4.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 2;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 0, 0, 0);
    add(this.m_jKey4, localGridBagConstraints);
    this.m_jKey7.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn7a.png")));
    this.m_jKey7.setFocusPainted(false);
    this.m_jKey7.setFocusable(false);
    this.m_jKey7.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey7.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 1;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 0, 0, 0);
    add(this.m_jKey7, localGridBagConstraints);
    this.m_jCE.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btnce.png")));
    this.m_jCE.setFocusPainted(false);
    this.m_jCE.setFocusable(false);
    this.m_jCE.setMargin(new Insets(8, 16, 8, 16));
    this.m_jCE.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 0;
    localGridBagConstraints.gridy = 0;
    localGridBagConstraints.gridwidth = 2;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    add(this.m_jCE, localGridBagConstraints);
    this.m_jMinus.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btnminus.png")));
    this.m_jMinus.setFocusPainted(false);
    this.m_jMinus.setFocusable(false);
    this.m_jMinus.setMargin(new Insets(8, 16, 8, 16));
    this.m_jMinus.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 2;
    localGridBagConstraints.gridy = 0;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(0, 5, 0, 0);
    add(this.m_jMinus, localGridBagConstraints);
    this.m_jKey9.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn9a.png")));
    this.m_jKey9.setFocusPainted(false);
    this.m_jKey9.setFocusable(false);
    this.m_jKey9.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey9.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 2;
    localGridBagConstraints.gridy = 1;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 5, 0, 0);
    add(this.m_jKey9, localGridBagConstraints);
    this.m_jKey8.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn8a.png")));
    this.m_jKey8.setFocusPainted(false);
    this.m_jKey8.setFocusable(false);
    this.m_jKey8.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey8.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 1;
    localGridBagConstraints.gridy = 1;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 5, 0, 0);
    add(this.m_jKey8, localGridBagConstraints);
    this.m_jKey5.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn5a.png")));
    this.m_jKey5.setFocusPainted(false);
    this.m_jKey5.setFocusable(false);
    this.m_jKey5.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey5.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 1;
    localGridBagConstraints.gridy = 2;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 5, 0, 0);
    add(this.m_jKey5, localGridBagConstraints);
    this.m_jKey6.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn6a.png")));
    this.m_jKey6.setFocusPainted(false);
    this.m_jKey6.setFocusable(false);
    this.m_jKey6.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey6.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 2;
    localGridBagConstraints.gridy = 2;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 5, 0, 0);
    add(this.m_jKey6, localGridBagConstraints);
    this.m_jKey3.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn3a.png")));
    this.m_jKey3.setFocusPainted(false);
    this.m_jKey3.setFocusable(false);
    this.m_jKey3.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey3.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 2;
    localGridBagConstraints.gridy = 3;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 5, 0, 0);
    add(this.m_jKey3, localGridBagConstraints);
    this.m_jKey2.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btn2a.png")));
    this.m_jKey2.setFocusPainted(false);
    this.m_jKey2.setFocusable(false);
    this.m_jKey2.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKey2.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 1;
    localGridBagConstraints.gridy = 3;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 5, 0, 0);
    add(this.m_jKey2, localGridBagConstraints);
    this.m_jKeyDot.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btndot.png")));
    this.m_jKeyDot.setFocusPainted(false);
    this.m_jKeyDot.setFocusable(false);
    this.m_jKeyDot.setMargin(new Insets(8, 16, 8, 16));
    this.m_jKeyDot.setRequestFocusEnabled(false);
    localGridBagConstraints = new GridBagConstraints();
    localGridBagConstraints.gridx = 2;
    localGridBagConstraints.gridy = 4;
    localGridBagConstraints.fill = 1;
    localGridBagConstraints.weightx = 1.0D;
    localGridBagConstraints.weighty = 1.0D;
    localGridBagConstraints.insets = new Insets(5, 5, 0, 0);
    add(this.m_jKeyDot, localGridBagConstraints);
    this.m_txtKeys.setPreferredSize(new Dimension(0, 0));
    this.m_txtKeys.addFocusListener(new FocusAdapter()
    {
      public void focusLost(FocusEvent paramFocusEvent)
      {
        JEditorKeys.this.m_txtKeysFocusLost(paramFocusEvent);
      }
    });
    this.m_txtKeys.addKeyListener(new KeyAdapter()
    {
      public void keyTyped(KeyEvent paramKeyEvent)
      {
        JEditorKeys.this.m_txtKeysKeyTyped(paramKeyEvent);
      }
    });
    add(this.m_txtKeys, new GridBagConstraints());
  }

  private void m_txtKeysKeyTyped(KeyEvent paramKeyEvent)
  {
    if (this.editorcurrent != null)
    {
      this.m_txtKeys.setText("0");
      char c = paramKeyEvent.getKeyChar();
      if (c == '\n')
        fireActionPerformed();
      else if (this.keysavailable == null)
        this.editorcurrent.typeChar(c);
      else
        for (int i = 0; i < this.keysavailable.length; i++)
        {
          if (c != this.keysavailable[i])
            continue;
          this.editorcurrent.typeChar(c);
        }
    }
  }

  private void m_txtKeysFocusLost(FocusEvent paramFocusEvent)
  {
    setInactive(this.editorcurrent);
  }

  private class MyKeyNumberListener
    implements ActionListener
  {
    private char m_cCad;

    public MyKeyNumberListener(char arg2)
    {
      char c;
      this.m_cCad = arg2;//ati
    }

    public void actionPerformed(ActionEvent paramActionEvent)
    {
      if (JEditorKeys.this.editorcurrent != null)
        JEditorKeys.this.editorcurrent.transChar(this.m_cCad);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.editor.JEditorKeys
 * JD-Core Version:    0.6.0
 */